{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "from common import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "RESULT_JSON = \"/Users/law/repos/viper/results/reclaim/reclaim_revision.json\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "BM_TYPES = ['WRITE', 'READ']\n",
    "\n",
    "BMS = get_all_runs(RESULT_JSON)\n",
    "# pprint(BMS) \n",
    "\n",
    "BM_TYPE_RE = re.compile(r'.*reclaim_fixed_(.+?)/.*/threads:(\\d+)')\n",
    "\n",
    "def get_reclaim_bm_type(bm_name):\n",
    "    match = BM_TYPE_RE.match(bm_name)\n",
    "    if match is None:\n",
    "        raise RuntimeError(f\"unknown bm type: {bm_name}\")\n",
    "    return (match.group(1), int(match.group(2)) == 33)\n",
    "\n",
    "RUNS = {}\n",
    "\n",
    "for bm in BMS:\n",
    "    reclaim_bm = get_reclaim_bm_type(bm['name'])\n",
    "    RUNS[reclaim_bm] = bm\n",
    "        \n",
    "# pprint(RUNS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots(1, 1, figsize=(3.5, 2.5))\n",
    "\n",
    "# Set position of bar on X axis\n",
    "bar_width = 0.30\n",
    "bar_diff = 0.02\n",
    "r1 = np.arange(2)\n",
    "r2 = [x + bar_width + bar_diff for x in r1]\n",
    "\n",
    "HATCHES = ['//', '', '\\\\\\\\', 'x']\n",
    "\n",
    "\n",
    "write_none = RUNS[('WRITE', False)]['items_per_second'] / MILLION\n",
    "write_recl = RUNS[('WRITE',  True)]['items_per_second'] / MILLION\n",
    "read_none =  RUNS[('READ',  False)]['items_per_second'] / MILLION\n",
    "read_recl =  RUNS[('READ',   True)]['items_per_second'] / MILLION\n",
    "\n",
    "#ax.bar(r1[0], write_none, bar_width, label=\"None\", edgecolor=COLORS[0], lw=2, hatch='//', color='white')\n",
    "#ax.bar(r2[0], write_recl, bar_width, label='Reclaim', color=COLORS[3], lw=2, edgecolor=COLORS[3])\n",
    "#ax.bar(r1[1], read_none, bar_width, edgecolor=COLORS[0], lw=2, hatch='//', color='white')\n",
    "#ax.bar(r2[1], read_recl, bar_width, color=COLORS[3], lw=2, edgecolor=COLORS[3])\n",
    "ax.bar(r1[0], write_none, bar_width, label=\"None\", color=DRAM_COLOR)\n",
    "ax.bar(r2[0], write_recl, bar_width, label='Reclaim', color=PMEM_COLOR)\n",
    "ax.bar(r1[1], read_none, bar_width, color=DRAM_COLOR)\n",
    "ax.bar(r2[1], read_recl, bar_width, color=PMEM_COLOR)\n",
    "\n",
    "\n",
    "ax.set_xticks([r + (0.5 * bar_width) for r in range(2)])\n",
    "ax.set_axisbelow(True)\n",
    "ax.grid(axis='y', which='major')\n",
    "for tick in ax.xaxis.get_major_ticks():\n",
    "    tick.label.set_fontsize(20)\n",
    "for tick in ax.yaxis.get_major_ticks():\n",
    "    tick.label.set_fontsize(18)\n",
    "\n",
    "\n",
    "ax.set_ylabel(\"Throughput\\n(Mops/s)\", fontsize=16)\n",
    "ax.set_xticklabels(['PUT', 'GET'], fontsize=16)\n",
    "\n",
    "# fig.legend(loc='upper center', bbox_to_anchor=(0.48, 1.15), \n",
    "#            ncol=2, frameon=False, fontsize=18, columnspacing=0.6, handletextpad=0.3)\n",
    "fig.legend(loc='upper center', bbox_to_anchor=(0.51, 0.94), \n",
    "           ncol=1, frameon=False, fontsize=16, columnspacing=0.4, handletextpad=0.2, \n",
    "           borderpad=0.1, labelspacing=0.1, handlelength=1.4)\n",
    "\n",
    "ax.spines['top'].set_visible(False)\n",
    "ax.spines['right'].set_visible(False)\n",
    "ax.spines['bottom'].set_visible(False)\n",
    "ax.spines['left'].set_visible(False)\n",
    "\n",
    "plt.tight_layout()\n",
    "fig.savefig('charts/reclaim.pdf', bbox_inches='tight')\n",
    "fig.savefig('charts/reclaim.svg', bbox_inches='tight')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
